package com.zc.study.thread.多线程第二章节.thread2_2_12;

import net.sf.ehcache.concurrent.Sync;

public class ThreadUtils extends Thread {
    private String userName ;
    public Object lock1 = new Object();
    public Object lock2 = new Object();

    public void setUserName(String userName){
        this.userName = userName;
    }
    public void method(){
        if (userName.equals("a")){
            synchronized (lock1){
                System.out.println(userName);
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (lock2){
                    System.out.println("hahahah");
                }
            }
        }else if(userName.equals("b")){
            synchronized (lock2){
                System.out.println(userName);
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (lock1){
                    System.out.println("hahahhaha");
                }
            }
        }
    }

}
